package pl.edu.agh.mbc.database;


import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
	private static final Logger LOG = Logger.getLogger(HibernateUtil.class);
	private static final SessionFactory HibSessionFactory;
	static {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			HibSessionFactory = new AnnotationConfiguration().configure()
					.buildSessionFactory();
		} catch (Throwable ex) {
			LOG.error("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return HibSessionFactory;
	}
	
	public static Session getCurrentSession(){
		return HibSessionFactory.getCurrentSession();	
	}
}
